/**
 * 判断是否是微信浏览器
 * @returns
 */
export const isWeChatBrowser = () =>
  /MicroMessenger/i.test(window.navigator.userAgent)
export const isMobile = () => {
  return window.screen.width < 768
}

function _isSaveWebpSupporte() {
  const canvas = document.createElement('canvas')
  canvas.width = 1
  canvas.height = 1
  const ctx = canvas.getContext('2d')
  ctx.fillStyle = 'green'
  ctx.fillRect(0, 0, 1, 1)
  const dataURL = canvas.toDataURL('image/webp')
  return dataURL.startsWith('data:image/webp')
}
let saveWebpSupported: boolean = null
/**
 * 判断浏览器是否支持webp格式
 */
export function isSaveWebpSupported() {
  if (saveWebpSupported === null) {
    saveWebpSupported = _isSaveWebpSupporte()
  }
  return saveWebpSupported
}

/**
 * 判断是不是在uniapp内嵌的webview环境内
 * @returns
 */
export function isUniapp() {
  // @ts-ignore
  return window.__uniapp_flag__ == true
}
